package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.PrintOrderBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 */

public class PrintDetailAdapter extends BaseAdapter {

    private List<PrintOrderBean.OrderDetailBean> objects = new ArrayList<PrintOrderBean.OrderDetailBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public PrintDetailAdapter(Context context, List<PrintOrderBean.OrderDetailBean> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public PrintOrderBean.OrderDetailBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_print_detail_goods_list, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((PrintOrderBean.OrderDetailBean) getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(PrintOrderBean.OrderDetailBean object, ViewHolder holder) {
        holder.tvGoodsName.setText(object.getName());
        holder.tvGoodNum.setText(object.getNum());
        holder.tvGoodsUnit.setText(object.getUnit());
        holder.tvGoodsPrice.setText(object.getPrice());
        holder.tvTotalMoney.setText(object.getTotal());
    }

    protected class ViewHolder {
        private TextView tvGoodsName;
        private TextView tvGoodsUnit;
        private TextView tvGoodNum;
        private TextView tvGoodsPrice;
        private TextView tvTotalMoney;

        public ViewHolder(View view) {
            tvGoodsName = (TextView) view.findViewById(R.id.tv_goods_name);
            tvGoodsUnit = (TextView) view.findViewById(R.id.tv_goods_unit);
            tvGoodNum = (TextView) view.findViewById(R.id.tv_good_num);
            tvGoodsPrice = (TextView) view.findViewById(R.id.tv_goods_price);
            tvTotalMoney = (TextView) view.findViewById(R.id.tv_total_money);
        }
    }


}
